package org.yzh.web.service.mq.impl;

import io.github.yezhihao.netmc.core.annotation.AsyncBatch;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yzh.commons.util.JsonUtils;
import org.yzh.protocol.basics.JTMessage;
import org.yzh.protocol.t808.T0200;
import org.yzh.web.enums.MqMsgTypeEnum;
import org.yzh.web.service.mq.IMqService;

import java.util.List;

@Service
public class MqServiceImpl implements IMqService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @AsyncBatch(poolSize = 2, maxElements = 4000, maxWait = 1000)
    @Override
    public void sendMsg(JTMessage jtMessage, MqMsgTypeEnum msgType) {
        rabbitTemplate.convertAndSend(msgType.getCode(), JsonUtils.toJson(jtMessage));
    }

    @Override
    public void sendOffLine(String clientId) {
        rabbitTemplate.convertAndSend(MqMsgTypeEnum.OFFLINE.getCode(), clientId);
    }

    @AsyncBatch(poolSize = 2, maxElements = 4000, maxWait = 1000)
    @Override
    public void sendGpsMsg(List<T0200> list) {
        rabbitTemplate.convertAndSend(MqMsgTypeEnum.GPS.getCode(), JsonUtils.toJson(list));
    }
}
